package com.xxxx.seckill.controller;

import com.xxxx.seckill.pojo.dto.LoginDto;
import com.xxxx.seckill.service.IUserService;
import com.xxxx.seckill.vo.RespBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

@Controller
@RequestMapping("/login")
@Slf4j
public class LoginController {

    @Autowired
    private IUserService iUserService;

    /**
     * 跳转登陆页面
     * @return
     */
    @GetMapping("/toLogin")
    public String toLigin(){
        return "login";
    }

    @PostMapping("/doLogin")
    @ResponseBody
    public RespBean dologin(@Valid LoginDto loginDto , HttpServletRequest request , HttpServletResponse resp){
        RespBean respBean = iUserService.login(loginDto,request,resp);
        return respBean;
    }
}
